﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Entities;

public partial class ProcessList : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["AdminName"] == null)
            Response.Redirect("login.aspx");


        if (!Page.IsPostBack)
        {
            DAL.FlowDALs flow = new DAL.FlowDALs();
            this.GridView2.DataSource = flow.GetList(null,null);
            string[] keys ={ "flow_id" };
            this.GridView2.DataKeyNames = keys;
            this.GridView2.DataBind(); 
        }
        
    }
    protected void OnPageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        GridView2.PageIndex = e.NewPageIndex;
        DAL.FlowDALs flow = new DAL.FlowDALs();
        this.GridView2.DataSource = flow.GetList(null, null);
        string[] keys ={ "flow_id" };
        this.GridView2.DataKeyNames = keys;
        this.GridView2.DataBind(); 
    }

    public String GtCheckUserByUserId(Object id)
    {
        DAL.UserDALs userdals = new DAL.UserDALs();

        int intID = int.Parse(id.ToString());
        String CheckUserName = userdals.GetCheckUserByUserId(intID);
        return CheckUserName;
    }
    protected void cmdSearch_Click(object sender, EventArgs e)
    {
        DAL.FlowDALs flow = new DAL.FlowDALs();
        if (ddlType.SelectedValue == "" && ddlStatus.SelectedValue != "") this.GridView2.DataSource = flow.GetList(null, Convert.ToInt16(ddlStatus.SelectedValue));
        else if (ddlType.SelectedValue != "" && ddlStatus.SelectedValue == "") this.GridView2.DataSource = flow.GetList(Convert.ToInt16(ddlType.SelectedValue), null);
        else if (ddlType.SelectedValue == "" && ddlStatus.SelectedValue == "") this.GridView2.DataSource = flow.GetList(null, null);
        else
        this.GridView2.DataSource = flow.GetList(Convert.ToInt16(ddlType.SelectedValue), Convert.ToInt16(ddlStatus.SelectedValue));
        
        string[] keys ={ "flow_id" };
        this.GridView2.DataKeyNames = keys;
        this.GridView2.DataBind();
    }

    protected string DGFormatSex(string xb)
    {
        if (xb == "0")
            return "未审核";
        else if (xb == "1")
            return "审核通过";
        else
            return "审核未通过";
    }

    protected string GetUserName(string user_id)
    {
        //int id = Convert.ToInt32(GridView1.DataKeys[e.NewEditIndex].Value);
        //DAL.FlowDALs flowdals = new DAL.FlowDALs();
        //Flow flow = flowdals.GetByID(id);
        //DAL.UserDALs userdals = new DAL.UserDALs();
        //User user = userdals.GetByID(flow.User_id);
        //return user.User_name;
        DAL.UserDALs userdals = new DAL.UserDALs();
        User user = userdals.GetByID(int.Parse(user_id));
        return user.User_name;
    }

    protected string GetCheckUserName(string checkuserid)
    {
        if (checkuserid == "") return "";
        DAL.UserDALs userdals = new DAL.UserDALs();
        User user = userdals.GetByID(int.Parse(checkuserid));
        return user.User_name;
    }


    protected void GridView2_RowEditing(object sender, GridViewEditEventArgs e)
    {
        int id = Convert.ToInt32(GridView2.DataKeys[e.NewEditIndex].Value);
        this.Response.Redirect("AddProcess.aspx?flow_id="+id);
    }
    protected void GridView2_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        int flowid = Convert.ToInt32(GridView2.DataKeys[e.RowIndex].Value);
        DAL.FlowDALs flowdals = new DAL.FlowDALs();
        flowdals.deleteFlow(flowid);
        this.GridView2.DataSource = flowdals.GetList(null, null);
        string[] keys ={ "flow_id" };
        this.GridView2.DataKeyNames = keys;
        this.GridView2.DataBind(); 
    }
}
